//
// Created by 19854 on 23/04/30.
//

#include "OLEDTask.h"

TaskHandle_t OLEDTaskHand;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void OLEDTask(void *ptParam)
{


//    U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 27, /* data=*/ 14, /* reset=*/ U8X8_PIN_NONE);
    U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
    u8g2.begin();
    u8g2.enableUTF8Print();
    u8g2.setFont(u8g2_font_unifont_t_chinese2);  // use chinese2 for all the glyphs of "你好世界"
    u8g2.setFontDirection(0);

    while (true)
    {
        uint32_t notifyVal=ulTaskNotifyTake(pdTRUE, //pdTRUE 运行完后，清零
                                   portMAX_DELAY);
//        Serial.print("收到通知:");
//        Serial.print(notifyVal);
        DateTime now(notifyVal);
        Serial.print(now.year(), DEC);
        Serial.print('/');
        Serial.print(now.month(), DEC);
        Serial.print('/');
        Serial.print(now.day(), DEC);
        Serial.print(" (");
        Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
        Serial.print(") ");
        Serial.print(now.hour(), DEC);
        Serial.print(':');
        Serial.print(now.minute(), DEC);
        Serial.print(':');
        Serial.print(now.second(), DEC);
        Serial.println();

        String date=(String)now.year()+" / "+(String)now.month()+" / "+(String)now.day();

//        date+=now.year();
//        date+=" / ";
//        date+=now.month();
//        date+=" / ";
//        date+=now.day();

        String time="";
        time+=now.hour();
        time+=" : ";
        time+=now.minute();
        time+=" : ";
        time+=now.second();

        u8g2.clearBuffer();
        u8g2.setCursor(0, 15);
        u8g2.print(date);
        u8g2.setCursor(0, 40);
        u8g2.print(time);		// Chinese "Hello World"
        u8g2.sendBuffer();
    }
}